package packVistas;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableColumn;
import javax.swing.JLabel;
import javax.swing.BoxLayout;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;

import java.awt.Component;
import java.awt.FlowLayout;

import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;

import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.JTable;

import java.awt.Dimension;

import javax.swing.JScrollPane;
import javax.swing.JScrollBar;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class GestionCambios2 extends JFrame {

	private JPanel contentPane;
	private JTable table;

	public GestionCambios2() {
		setTitle("Prueba");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 419, 485);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		JPanel norte = new JPanel();
		contentPane.add(norte, BorderLayout.NORTH);
		norte.setLayout(new FormLayout(new ColumnSpec[] {},
			new RowSpec[] {}));
		
		JPanel sur = new JPanel();
		contentPane.add(sur, BorderLayout.SOUTH);
		
		JPanel oeste = new JPanel();
		contentPane.add(oeste, BorderLayout.WEST);
		
		JPanel este = new JPanel();
		contentPane.add(este, BorderLayout.EAST);
		
		JPanel centro = new JPanel();
		contentPane.add(centro, BorderLayout.CENTER);
		centro.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("center:max(114dlu;default):grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("center:default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("top:max(21dlu;default)"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("min(50dlu;default):grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,}));
		
		JLabel lblNewLabel = new JLabel("Partido:");
		centro.add(lblNewLabel, "2, 2, right, default");
		
		JComboBox comboBox = new JComboBox();
		comboBox.addItem("Partido 1");
		comboBox.addItem("Partido 2");
		comboBox.addItem("Partido 3");
		comboBox.addItem("Partido 4");
		comboBox.addItem("Partido 5");

		centro.add(comboBox, "4, 2, left, default");
		
		JLabel lblNewLabel_1 = new JLabel("Seleccionar equipo para el cambio:");
		centro.add(lblNewLabel_1, "2, 4, 3, 1, left, default");
		
		JPanel panel = new JPanel();
		centro.add(panel, "2, 6, left, top");
		
		JRadioButton rdbtnNewRadioButton = new JRadioButton("New radio button");
		panel.add(rdbtnNewRadioButton);
		
		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("New radio button");
		panel.add(rdbtnNewRadioButton_1);
		
		JLabel lblNewLabel_2 = new JLabel("New label");
		centro.add(lblNewLabel_2, "2, 8, right, default");
		
		JSpinner spinner = new JSpinner();
		centro.add(spinner, "4, 8, left, default");
		
		JLabel lblNewLabel_3 = new JLabel("Jugador retirado");
		centro.add(lblNewLabel_3, "2, 10");
		
		JLabel lblNewLabel_4 = new JLabel("Jugador incorporado");
		centro.add(lblNewLabel_4, "4, 10");
		
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setPreferredSize(new Dimension(100, 20));
		comboBox_1.addItem("Jugador 1");

		centro.add(comboBox_1, "2, 12, center, default");
		
		JComboBox comboBox_2 = new JComboBox();
		comboBox_2.addItem("Jugador 2");

		centro.add(comboBox_2, "4, 12, center, default");
		
		JButton btnNewButton_2 = new JButton("anotar incidencia");
		centro.add(btnNewButton_2, "2, 14, 3, 1, center, default");
		
		
		//Creamos las columnas
		String[] columnas = new String[] {"Jugador", "minuto",  "ID"};
		
		//Datos de la tabla
		Object[][] datos = new Object[][] {
				{"Jugador 1", 70,1},
				{"Jugador 2", 80,2},
				{"Jugador 3", 90,3},
		};
		
		JScrollPane scrollPane = new JScrollPane();
		centro.add(scrollPane, "2, 16, fill, fill");
		
		table = new JTable(datos,columnas);
		table.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
			String miid = table.getValueAt(table.getSelectedRow(), 1).toString();
				JOptionPane.showMessageDialog(new JFrame(), 
						"El id seleccionado es " + miid, 
						getTitle(),JOptionPane.INFORMATION_MESSAGE);
			}
		});
		
		TableColumn column = table.getColumnModel().getColumn(2);
	    column.setMinWidth(0);
	    column.setMaxWidth(0);
	    column.setWidth(0);
	    column.setPreferredWidth(0);
		
		scrollPane.setViewportView(table);
		
		JButton btnNewButton = new JButton("Borrar incidencia");
		centro.add(btnNewButton, "2, 18");
		
		JButton btnNewButton_1 = new JButton("cancelar");
		centro.add(btnNewButton_1, "4, 18");
	}
}
